# -*- coding: UTF-8 -*-
from django.db import models
from django.contrib.auth.models import User
from django import forms
from django.db import models

# Create your models here.
# Create your models here.
# Opisuje wszystkie możliwe do użycia przełączniki.
# Na podstawie tych wartości generowanych jest widok
# dla użytkownika (true/false - pokaż/ukryj).
class TraceroutePermissionForOption(models.Model):
    # Bind permission to the user
    user = models.ForeignKey(User)
    IPv4Option = models.BooleanField(default=1, verbose_name="-IPv4")
    IPv6Option = models.BooleanField(default=1, verbose_name="-IPv6")
    dOption = models.BooleanField(default=1, verbose_name="-d")
    F_Option = models.BooleanField(default=1, verbose_name="-F")
    I_Option = models.BooleanField(default=1, verbose_name="-I")
    T_Option = models.BooleanField(default=1, verbose_name="-T")
    U_Option = models.BooleanField(default=1, verbose_name="-U")
    nOption = models.BooleanField(default=1, verbose_name="-n")
    rOption = models.BooleanField(default=1, verbose_name="-r") 
    eOption = models.BooleanField(default=1, verbose_name="-e")
    A_Option = models.BooleanField(default=1, verbose_name="-A")
    V_Option = models.BooleanField(default=1, verbose_name="-V")

# Opisuje wszystkie możliwe do użycia parametry.
# Na podstawie tych wartości generowanych jest widok
# dla użytkownika (true/false - pokaż/ukryj).
class TraceroutePermissionForParameter(models.Model):
    # Bind permission to the user
    user = models.ForeignKey(User)
    fOption = models.BooleanField(default=1, verbose_name="-t first_ttl")
    gOption = models.BooleanField(default=1, verbose_name="-g gateway")
    iOption = models.BooleanField(default=1, verbose_name="-i iface")
    mOption = models.BooleanField(default=1, verbose_name="-m max_ttl")
    pOption = models.BooleanField(default=1, verbose_name="-p port")
    qOption = models.BooleanField(default=1, verbose_name="-q nqueries")
    sOption = models.BooleanField(default=1, verbose_name="-s src_addr")
    tOption = models.BooleanField(default=1, verbose_name="-t tos")
    wOption = models.BooleanField(default=1, verbose_name="-w waittime")
    zOption = models.BooleanField(default=1, verbose_name="-z pausemsecs")

# Opisuje formularz, jaki zostanie wygenerowany dla parametrów polecenia.
# Definiuje walidację danego pola, jego etykietę oraz tekst podpowiedzi.
class TracerouteFormForParameters(forms.Form):
    fOption = forms.IntegerField(
        required = False,
        label = '-t',
        help_text = 'first_ttl',
        min_value = 1,)
    gOption = forms.CharField(
        max_length=128,
        required = False,
        label = '-g',
        help_text = 'gateway')
    iOption = forms.CharField(
        max_length=128,
        required = False,
        label = '-i',
        help_text = 'iface')
    mOption = forms.IntegerField(
        required = False,
        label = '-m',
        help_text = 'max_ttl',
        min_value = 1,)
    pOption = forms.IntegerField(
        required = False,
        label = '-p',
        help_text = 'port',
        min_value = 1,)
    qOption = forms.IntegerField(
        required = False,
        label = '-q',
        help_text = 'nqueries',
        min_value = 1,)
    sOption = forms.CharField(
        max_length=128,
        required = False,
        label = '-s',
        help_text = 'src_addr',)
    tOption = forms.IntegerField(
        required = False,
        label = '-t',
        help_text = 'tos',
        min_value = 0,
        max_value = 255,)
    wOption = forms.IntegerField(
        required = False,
        label = '-w',
        help_text = 'waittime',
        min_value = 1,)
    zOption = forms.IntegerField(
        required = False,
        label = '-z',
        help_text = 'pausemsecs',
        min_value = 1,)

# Opisuje formularz, jaki zostanie wygenerowany dla parametrów polecenia.
# Definiuje walidację danego pola, jego etykietę oraz tekst podpowiedzi.
class HostForm(forms.Form):
    host = forms.CharField(
        max_length = 128,
        required = True,
        help_text = 'host',)

# Opisuje formularz, jaki zostanie wygenerowany dla opcji polecenia.
# Definiuje walidację danego pola, jego etykietę oraz tekst podpowiedzi.
class TracerouteFormForOptions(forms.Form):
    IPv4Option = forms.BooleanField(
        required = False,
        label = '-4',
        help_text = 'Explicitly force IPv4 traceouting.')
    IPv6Option = forms.BooleanField(
        required = False,
        label = '-6',
        help_text = 'Explicitly force IPv6 traceouting.')
    dOption = forms.BooleanField(
        required = False,
        label = '-d',
        help_text = 'Enable  socket  level  debugging (when the Linux kernel supports it).')
    F_Option = forms.BooleanField(
        required = False,
        label = '-F',
        help_text = 'Do not fragment probe packets. (For IPv4 it also  sets  DF  bit, which  tells  intermediate  routers  not to fragment remotely as well).')
    I_Option = forms.BooleanField(
        required = False,
        label = '-I',
        help_text = 'Use ICMP ECHO for probes.')
    T_Option = forms.BooleanField(
        required = False,
        label = '-T',
        help_text = 'Use TCP SYN for probes.')
    nOption = forms.BooleanField(
        required = False,
        label = '-n',
        help_text = 'Do not try to map IP addresses to  host  names  when  displaying them.')
    rOption = forms.BooleanField(
        required = False,
        label = '-r',
        help_text = 'Bypass  the normal routing tables and send directly to a host on an attached network. If the host is not on a directly-attached network, an error is returned.  This option can be used to ping a local host through an interface that has no route through it.')
    eOption = forms.BooleanField(
        required = False,
        label = '-e',
        help_text = 'Show ICMP extensions (rfc4884). The general form is CLASS/TYPE:followed by a hexadecimal dump. The MPLS (rfc4950) is shown parsed, in  a form: MPLS:L=label,E=exp_use,S=stack_bottom,T=TTL (more objects separated by / ).')
